<template>
	<view class="page" :style="themeColor">

		<view class="flex flex-direction flex-wrap align-stretch">
			<view class='flex flex-direction flex-wrap align-center login_fd0_0'>
				<image class='login_fd0_0_c0' mode="aspectFill" :src='STATIC_URL+"2.png"'></image>
				<view class="logo_name">智海马科技火箭版</view>
			</view>
			<view class="title_text">
				<text>——</text>
				<text class="title_text_1">欢迎使用</text>
				<text>——</text>
			</view>
			<view class='flex flex-wrap align-center login_fd0_1'>
				<image class='login_fd0_1_c0' mode="aspectFill" :src='STATIC_URL+"3.png"'></image>
				<input class='flex-sub login_fd0_1_c1' type="text" placeholder="请输入用户名/手机号" confirm-type="done"
					:maxlength="15" placeholder-style="color:rgba(153, 153, 153, 1);font-size:25rpx"
					v-model="account" />
			</view>
			<view class='flex flex-wrap align-center login_fd0_2'>
				<image class='login_fd0_1_c0' mode="aspectFill" :src='STATIC_URL+"4.png"'></image>
				<benben-flex-password-diy v-model="password" class-name="flex align-center flex-sub flex login_fd0_2_c1"
					:placeholder="'请输入密码(6~12位字母+数字)'" :maxlength="12" :default-type='true'
					placeholder-style="color:rgba(153, 153, 153, 1);font-size:25rpx">
					<template #show>
						<text class='fu-iconfont2  login_fd0_2_c1_icon1' data-type="show">&#xE837;</text>
					</template>
					<template #hide>
						<text class='fu-iconfont2  login_fd0_2_c1_icon1' data-type="hide">&#xEBCC;</text>
					</template>
				</benben-flex-password-diy>
			</view>
			<!-- <text class='self-end login_fd0_3' @tap.stop="handleJumpDiy" data-type="navigateTo"
				:data-url="`/pages/dlzc/codeLogin/codeLogin`">验证码登录</text> -->
			<view class='flex align-center justify-center'>
				<button class='login_fd0_4_c0' @tap.stop="goLoginFunc()">登录</button>
			</view>
			<view class='flex flex-wrap align-center justify-center login_fd0_5'>
				<text class='login_fd0_5_c0' @tap.stop="handleJumpDiy" data-type="navigateTo"
					:data-url="`/pages/dlzc/register/register`">注册账号 </text>
				<view class='flex flex-wrap align-center login_fd0_5_c1'>
				</view>
				<text class='login_fd0_5_c0' @tap.stop="handleJumpDiy" data-type="navigateTo"
					:data-url="`/pages/dlzc/forgetPwd/forgetPwd`">忘记密码</text>
			</view>
		</view>
		
		<uv-modal width="300rpx" :showCancelButton="true" :closeOnClickOverlay="false" confirmColor="#4087FD" ref="modal" title="提示"content='是否绑定设备？' align="center" @confirm="confirm" @cancel="cancel" :textStyle="{fontSize: 20 + 'px'}"></uv-modal>
	</view>
</template>
<script>
	import {
		validate
	} from '@/common/utils/validate.js'
	export default {
		components: {},


		data() {
			return {
				"account": "",
				"password": "",
				"userInfo": {
					"user_token": "",
					"id": "",
					"avatar": "",
					"real_name": "",
					"nickname": "",
					"gender": "",
					"mobile": "",
					"birthday": "",
					"phone": "",
					"email": "",
					"client_id": ""
				},
				"check": false,
				"is_click": false,
			};
		},
		computed: {
			themeColor() {
				return this.$store.getters.themeColor
			},

		},
		watch: {},
		onLoad(options) {
			
		},
		onUnload() {

		},
		onReady() {
			// this.$refs.modal.open();
		},
		onShow() {

		},
		onHide() {

		},
		onResize() {

		},
		onPullDownRefresh() {

		},
		onReachBottom(e) {

		},
		onPageScroll(e) {

		},
		methods: {
			// 弹窗确定按钮
			confirm() {
				this.$refs.modal.close();
				this.bindDevice();
			},
			cancel() {
				this.$refs.modal.close();
				this.$store.commit('logout');
			},
			//登录
			async goLoginFunc() {
				if (this.is_click) return;
				if (!validate(this.account, 'require')) {
					this.$message.info('用户名或手机号不能为空');
					return false;
				}
				// if (!validate(this.account, 'phone')) {
				// 	this.$message.info('请输入正确的手机号');
				// 	return false;
				// }
				if (!validate(this.password, 'require')) {
					this.$message.info('密码不能为空');
					return false;
				}
				if (!validate(this.password, 'password')) {
					this.$message.info('请输入6-12位字母+数字密码');
					return false;
				}
				this.is_click = true;
				uni.showLoading();

				let datauserInfo = await this.$api.post(global.apiUrls.post5c78dbfd977cf, {
					account: this.account,
					password: this.password
				});

				if (datauserInfo.data.code != 1) {
					uni.hideLoading();
					this.is_click = false;
					this.$message.info(datauserInfo.data.msg);
					return
				}
				let infouserInfo = datauserInfo.data;
				this.userInfo = infouserInfo.data.userinfo;
				this.$store.commit('saveToken', this.userInfo.user_token);
				this.$store.commit('updateUserInfo', this.userInfo);
				uni.hideLoading();
				// console.log(this.userInfo);
				if (this.userInfo.account_type == 1) {
					this.$message.info(datauserInfo.data.msg);
					setTimeout(() => {
						this.is_click = false;
						uni.reLaunch({
							url: '/pages/tabBar/index/index'
						})
					}, 800)
				} else {
					if (this.userInfo.is_bind == 1) {
						this.$message.info(datauserInfo.data.msg);
						setTimeout(() => {
							this.is_click = false;
							uni.reLaunch({
								url: '/pages/tabBar/index/index'
							})
						}, 800)
					} else {
						this.is_click = false;
						this.$refs.modal.open();
					}
					
				}
			},
			// 绑定设备
			bindDevice() {
				let _this = this;
				let client_id = "";
				
				// #ifdef APP-PLUS
				plus.device.getInfo({
					success: (e) => {
						// console.log(e)
						client_id = e.uuid
						if (client_id) {
							_this.$api.post(global.apiUrls.post65969704bfa7d, {
								equipment_code: client_id
							}).then(res => {
								// console.log(res);
								if (res.data.code == 1) {
									_this.$message.info('绑定成功');
									setTimeout(() => {
										uni.reLaunch({
											url: '/pages/tabBar/index/index'
										})
									}, 800)
								} else {
									_this.$message.info(res.data.msg);
								}
							})
						} else {
							_this.$message.info('获取设备id失败，请联系管理员')
						}
						
					},
					fail: function(e) {
						_this.$message.info('获取设备id失败，请联系管理员')
					}
				});
				// #endif
				
				// #ifndef APP-PLUS
				_this.$message.info('绑定成功');
				setTimeout(() => {
					uni.reLaunch({
						url: '/pages/tabBar/index/index'
					})
				}, 800)
				// #endif
			},
			
		}
	};
</script>
<style lang="scss" scoped>
	.logo_name {
		font-size: 28rpx;
		color: #4087FD;
		margin: 25rpx auto 0;
	}

	.title_text {
		margin: 86rpx auto 50rpx;
		color: #DDDDDD;
		.title_text_1 {
			color: #666666;
			margin: 0 18rpx;
			font-size: 25rpx;
		}
	}

	.page {
		width: 100vw;
		overflow-x: hidden;
		min-height: calc(100vh - var(--window-bottom));
		background: rgba(255, 255, 255, 1);
		background-size: 100% auto !important;
		background: url(/static/images/1.png) no-repeat, #fff;
		background-size: 100% auto !important;
	}

	.login_fd0_5_c1 {
		background: rgba(191, 191, 191, 1);
		width: 1rpx;
		height: 24rpx;
		background-size: 100% auto !important;
		margin: 0rpx 32rpx 0rpx 32rpx;
	}

	.login_fd0_5_c0 {
		font-size: 20rpx;
		font-weight: 400;
		color: #999999;
		line-height: 40rpx;
	}

	.login_fd0_5 {
		line-height: 40rpx;
		margin: 50rpx 0rpx 0rpx 0rpx;
	}

	.login_fd0_4_c0 {
		background: #4087FD;
		border-radius: 44rpx 44rpx 44rpx 44rpx;
		font-size: 25rpx;
		color: #fff;
		height: 68rpx;
		line-height: 68rpx;
		font-weight: 500;
		width: 625rpx;
		margin-top: 150rpx;
	}

	.login_fd0_3 {
		line-height: 40rpx;
		font-size: 28rpx;
		font-weight: 400;
		color: #333333;
		margin: 32rpx 55rpx 48rpx 0rpx;
	}

	.login_fd0_2_c1_icon1 {
		// width: 88rpx;
		// line-height: 88rpx;
		text-align: center;
		font-size: 44rpx;
	}

	::v-deep .login_fd0_2_c1 {
		// height: 125rpx;
		// width: 570rpx;
		font-size: 25rpx;
		font-weight: 400;
		color: #333;
	}

	.login_fd0_2 {
		padding: 20rpx 40rpx 20rpx 40rpx;
		margin: 0rpx 63rpx 0rpx 63rpx;
		background: #f8f8f8;
		border-radius: 38rpx;
		margin-top: 40rpx;
	}

	.login_fd0_1_c1 {
		line-height: 45rpx;
		font-size: 25rpx;
		font-weight: 400;
		color: #333;
		width: 100%;
	}

	.login_fd0_1_c0 {
		width: 28rpx;
		height: 28rpx;
		margin: 0rpx 22rpx 0rpx 0rpx;
	}

	.login_fd0_1 {
		background: #f8f8f8;
		padding: 20rpx 40rpx 20rpx 40rpx;
		margin: 0rpx 63rpx 0rpx 63rpx;
		border-radius: 38rpx;
	}

	.login_fd0_0_c0 {
		width: 150rpx;
		height: 150rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;

	}

	.login_fd0_0 {

		// height: 600rpx;
		margin: 125rpx 0rpx 0rpx 0rpx;
	}

	.login_flex_1 {
		background: #fff;
		width: 100%;
		height: 300rpx;
		overflow: hidden;
		z-index: 10;
		bottom: calc(0rpx + var(--window-bottom));
		background-size: 100% auto !important;
	}

	.login_fd1_1 {
		width: 80rpx;
		height: 80rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		margin: 40rpx 0rpx 0rpx 0rpx;
	}

	.login_fd1_0_c1 {
		line-height: 32rpx;
		font-size: 26rpx;
		font-weight: 400;
		color: #999999;
		padding: 0rpx 7rpx 0rpx 7rpx;
	}

	.login_fd1_0_c0 {
		background: rgba(238, 238, 238, 1);
		background-size: 100% auto !important;
		height: 1rpx;
		width: 157rpx;
	}
</style>